import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from agent import WindowAgent
import time

print("=== 简单浏览器示例 ===")

def main():
    agent = WindowAgent()
    
    if agent.start_browser("chrome"):
        try:
            # 访问简单页面
            print("访问 example.com...")
            agent.browser_navigate("https://example.com")
            time.sleep(2)
            
            # 获取页面标题
            title = agent.browser.get_page_title()
            print(f"页面标题: {title}")
            
            # 截屏
            if agent.browser_screenshot("example.png"):
                print("截屏成功: example.png")
            
            # 访问另一个页面
            print("\n访问 Python 官网...")
            agent.browser_navigate("https://www.python.org")
            time.sleep(3)
            
            title = agent.browser.get_page_title()
            print(f"页面标题: {title}")
            
            if agent.browser_screenshot("python_org.png"):
                print("截屏成功: python_org.png")
                
        except Exception as e:
            print(f"错误: {e}")
        finally:
            print("\n关闭浏览器...")
            time.sleep(2)
            agent.close_browser()

if __name__ == "__main__":
    main()
